package com.eoe.wiki.activity;


import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;

import com.eoe.wiki.R;
import com.eoe.wiki.db.dao.UpdateDao;
import com.eoe.wiki.db.dao.WikiDao;
import com.eoe.wiki.json.CategoryJson;

public abstract class CategoryActivity extends SliderActivity{

	private final static int HANDLER_DISPLAY_CATEGORY = 0x0001;
	private final static int HANDLER_LOAD_CATEGORY_ERROR = 0x0002;
	private final static int HANDLER_LOAD_CATEGORY_DB = 0x0003;
	private final static int HANDLER_LOAD_CATEGORY_NET = 0x0004;
	private final static int HANDLER_REFRESH_CATEGORY_NET = 0x0005;
	private final static int HANDLER_DISPLAY_RECENT_UPDATE = 0x0006;
	
	protected CategoryJson mResponseObject = null;
	private String mUrl = null;
	private WikiDao mWikiDao = null;
	private UpdateDao mUpdateDao = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		mWikiDao = new WikiDao(mContext);
		mUpdateDao = new UpdateDao(mContext);
	}
	
	void getCategory(String url){
		if(TextUtils.isEmpty(url)){
			throw new IllegalArgumentException("you must giew a not empty url");
		}
		this.mUrl = url;
		mHandler.sendEmptyMessage(HANDLER_LOAD_CATEGORY_DB);
	}

	abstract void getCategoriesError(String showText);
    abstract void generateCategories(CategoryJson responseObject);
	private Handler mHandler = new Handler(){
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case HANDLER_DISPLAY_CATEGORY:
				generateCategories((CategoryJson)msg.obj);
				break;
			case HANDLER_LOAD_CATEGORY_ERROR:
				getCategoriesError(getString(R.string.tip_get_category_error));
				break;
			case HANDLER_DISPLAY_RECENT_UPDATE:
				break;
			case HANDLER_LOAD_CATEGORY_DB:
				break;
			case HANDLER_LOAD_CATEGORY_NET:
				break;
			case HANDLER_REFRESH_CATEGORY_NET:
				break;
			default:
				break;
			}
		};
	};
	
}
